package com.offcn.movie.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.offcn.bean.ConditionBean;
import com.offcn.bean.Moviedetailtable;
import com.offcn.bean.Movietable;
import com.offcn.movie.dao.MovieDao;
import com.offcn.movie.dao.MovieDetailDao;
import com.offcn.movie.service.MovieService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
@Service
public class MovieServiceImpl implements MovieService{
    @Resource
    private MovieDao movieDao;
    @Resource
    private MovieDetailDao movieDetailDao;

    @Override
    public List<Movietable> queryMovieList(String back) {
        List<Movietable> ms = null;
        if("back".equals(back)){
            ms = movieDao.selectMovieList(9);
        }
        return ms;
    }


    @Override
    //fromS参数用来设置请求是从前台还是后台来的
    public PageInfo<Movietable> queryMovieList1(int pagenum, int currentPage, ConditionBean conditionBean) {
        PageHelper.startPage(currentPage,pagenum);
        List<Movietable> list = movieDao.selectMovieList1(conditionBean);
        PageInfo<Movietable> pageInfo = new PageInfo<>(list,10);
        return pageInfo;

    }

    //增加电影信息---增加电影表和详情表
    @Transactional
    @Override
    public void save(Movietable movietable, Moviedetailtable moviedetailtable) {
        movieDao.insert(movietable);

        moviedetailtable.setId(movietable.getId());
        movieDetailDao.insert(moviedetailtable);
    }


}

